$(function () {
    $.get(
        "category?method=getCategories",
        function (data) {
            //[{"cid":XXXX,"cname":XXX},{"cid":XXXX,"cname":XXX}]
            //遍历json数据放入ul中
            var cList = $("#cList");
            $.each(data,function (i,v) {
                var li = "";
                if(i==0){
                    li = "<li class=\"active\"><a href='product?method=getProductsByCategoryId&cid="+v.cid+"'>"+v.cname+"<span class=\"sr-only\">(current)</span></a></li>";
                }else{
                    li = "<li><a href='product?method=getProductsByCategoryId&cid="+v.cid+"'>"+v.cname+"</a></li>";
                }
                cList.append(li);
            });
        },
        "json"
    );
});